home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 11 / CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso / s / insertdoc.pprx < prev    next >
Text File  |  1993-02-19  |  4KB  |  164 lines

  1. /*
  2. @BInsertDoc  @P@ICopyright Gold Disk Inc., Jan, 1993
  3.  
  4. This Genie will insert a previously saved document into the current document while maintaining all links between boxes.
  5.  
  6. */
  7. cr = '0a'x
  8. call SafeEndEdit.rexx()
  9. call ppm_AutoUpdate(0)
  10. call ppm_SetBatchMode(1)
  11.  
  12. prevdoc  = ppm_GetDocName()
  13.  
  14. if ppm_DocChanged() then
  15. do
  16.     if ppm_SavedDate() = "Not Saved" then prevdoc = ""
  17.  
  18.     if ppm_Inform(2, "You must save the current document first. Should I save and continue?", "Cancel", "Ok") then
  19.                 call ppm_SaveDocument(prevdoc)
  20.     else
  21.             exit_msg(0,)
  22.  
  23.     prevdoc = ppm_GetDocName()
  24. end
  25.  
  26. doc = ppm_GetFileName("Select Document to insert", "", "")
  27. if doc = '' then exit
  28.  
  29. if ~ppm_LoadDocument(doc, 0, 0) then
  30.     exit_msg(0, "Unable to open document: "doc)
  31.  
  32. boxes = 0
  33.  
  34. call ppm_ShowStatus("Working..")
  35.  
  36. npages = ppm_NumPages()
  37.  
  38. box = ppm_DocFirstBox()
  39.  
  40. oldnames = 0
  41. text     = 1
  42. count    = 3
  43. article = 0
  44.  
  45. /*  cycle through all the boxes in the document */
  46. do while box ~= 0
  47.  
  48.  
  49.     info    = upper(ppm_GetBoxInfo(box))
  50.     fname   = word(ppm_GetBoxName(box), 1)
  51.  
  52.     /*  check if this is a box within a text link   */
  53.     if word(info, 1) = 'TEXT' & word(info, 3) ~= 1 & fname ~= "PGLNK" then
  54.     do
  55.             cbox = ppm_ArtFirstBox(box)
  56.         article = article + 1
  57.         links.article.oldnames = links.article.oldnames || '0a'x || fname
  58.         links.article.text      = ppm_GetArticleText(cbox, 1)
  59.         call ppm_DeleteContents(cbox)
  60.  
  61.         call ppm_SetBoxName(cbox, "PGLNK "article" 0")
  62.  
  63.         nextbox  = ppm_ArtNextBox(cbox)
  64.         counter = 0
  65.  
  66.         do while nextbox ~= 0
  67.  
  68.             counter = counter + 1
  69.             boxname = ppm_GetBoxName(nextbox)
  70.             links.article.oldnames = links.article.oldnames || '0a'x || boxname
  71.  
  72.             call ppm_SetBoxName(nextbox, "PGLNK "article" "counter)
  73.             nextbox = ppm_ArtNextBox(nextbox)
  74.  
  75.         end
  76.  
  77.         links.article.count = counter
  78.  
  79.     end
  80.  
  81.    box = ppm_DocNextBox(box)
  82.  
  83. end
  84.  
  85. /*  save all of the pages   */
  86. do page = 1 to npages
  87.  
  88.     if ~ppm_SavePage(page, "Ram:temppage"page) then
  89.                 exit_msg(page, "An error has occured while saving the pages to the Ram Disk.")
  90.  
  91. end
  92.  
  93. prevpage = page - 1
  94.  
  95. if ~ppm_LoadDocument(prevdoc, 1, 0) then
  96.     exit_msg(prevpage, "An error has occured reloading the original document")
  97.  
  98. cpage = ppm_DocLastPage()
  99. startpage = ppm_GetForm("Insert after Page", 8, "Page:"cpage)
  100. if startpage = '' then exit_msg(prevpage, "")
  101.  
  102. if ~datatype(startpage, n) then exit_msg("Invalid Input")
  103.  
  104. do  page  = 1 to prevpage
  105.  
  106.     if ~ppm_LoadPage(startpage + 1, "Ram:temppage"page, 1) then
  107.                 exit_msg(prevpage, "Error opening saved page")
  108.  
  109.     startpage = startpage + 1
  110. end
  111.  
  112. /*  relink boxes    */
  113. do art = 1 to article
  114.  
  115.     prefix = "PGLNK "art
  116.     prevbox = ppm_BoxNum(prefix" 0")
  117.     if prevbox = 0 then exit_msg("Error! Unable to re-establish links!")
  118.  
  119.     firstbox = prevbox
  120.  
  121.     parse var links.art.oldnames junk '0a'x fbname '0a'x links.art.oldnames
  122.  
  123.     call ppm_SetBoxName(prevbox, fbname)
  124.  
  125.     do boxcount = 1 to links.art.count
  126.  
  127.         nextbox = ppm_BoxNum(prefix" "boxcount)
  128.         if boxcount = 0 then
  129.             exit_msg("Error! Unable to re-establish links!")
  130.  
  131.         call ppm_LinkBox(prevbox, nextbox)
  132.  
  133.         parse var links.art.oldnames boxname '0a'x links.art.oldnames
  134.         call ppm_SetBoxName(nextbox, boxname)
  135.  
  136.         prevbox = nextbox
  137.  
  138.     end
  139.  
  140.     call ppm_TextIntoBox(firstbox, links.art.text)
  141.  
  142. end
  143.  
  144. exit_msg(prevpage, "Done")
  145.  
  146.  
  147. exit_msg: procedure
  148. do
  149.     parse arg pages, message
  150.  
  151.     do pg = 1 to pages
  152.             call Delete("ram:temppage"pg)
  153.     end
  154.  
  155.     if message ~= '' then
  156.     call ppm_Inform(1, message, )
  157.  
  158.     call ppm_AutoUpdate(1)
  159.     call ppm_ClearStatus()
  160.     call ppm_SetBatchMode(1)
  161.     exit
  162. end
  163.  
  164.